Skip to content

feat(keycloak): add shared Keycloak instance - #2

Open
JSisques wants to merge 1 commit into
mainfrom
JSisques/feat-add-keycloak
Open

feat(keycloak): add shared Keycloak instance#2
JSisques wants to merge 1 commit into
mainfrom
JSisques/feat-add-keycloak

Conversation

@JSisques

@JSisques JSisques commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a shared Keycloak instance (quay.io/keycloak/keycloak:26.0) to the stack — it used to live only in account-api's own docker-compose.yml because it had a single consumer; now that more than one service needs it, it's centralized here like Postgres/Kafka/Redis/OTel.
  • Realms are registered as individual JSON files under docker/keycloak/realms/ (mirrors docker/postgres/init-db.sh's one-database-per-service pattern) and imported via a one-shot keycloak-realm-import job that calls the Admin REST API.
  • Migrated account-api's existing realm/client to docker/keycloak/realms/account-api-realm.json (companion PR removes the duplicate service from account-api's own compose file).

Why not Keycloak's own --import-realm flag

start-dev --import-realm reliably crashes Keycloak 26.0 on boot with ERROR: Session not bound to a realm, right after logging the realm as successfully imported. Reproduced repeatedly while adding this service, both with and without a persistent data volume, and both with and without the service-account role-mapping block in the realm JSON. Matches unresolved upstream reports: keycloak/keycloak#33637 and #34673. Worked around by starting Keycloak plain (start-dev) and importing realms after boot via POST /admin/realms from a separate curlimages/curl job instead — see docker/keycloak/import-realms.sh for details, and the README's "Keycloak" section for the full writeup.

No persistent data volume for Keycloak, by design — see the same README section.

Test plan

  • docker compose config -q
  • docker compose up -d — full stack up, every service healthy/running, keycloak-realm-import exits 0, keycloak never restarts
  • curl http://localhost:8084/realms/sisques-account/.well-known/openid-configuration → 200 after import
  • Re-running docker compose up -d keycloak-realm-import against an already-imported realm returns 409 and is treated as success (idempotent)
  • docker compose down -v — clean teardown, no dangling volumes

…re services

account-api's Keycloak used to live in its own docker-compose.yml because it
had exactly one consumer; now that more than one service needs it, it moves
here alongside the other shared infra (Postgres, Kafka, Redis, OTel).

Realms are imported via the Admin REST API by a one-shot
keycloak-realm-import job, not Keycloak's own --import-realm startup flag:
that flag reliably crashes Keycloak 26.0 on boot with "ERROR: Session not
bound to a realm" right after logging the realm import as successful
(reproduced repeatedly while adding this service; see upstream
keycloak/keycloak#33637 and #34673, unresolved as of image 26.0.8).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant